package com.sjksy.demo.controller;

import com.sjksy.demo.service.TravelContractService;
import com.sjksy.demo.service.TravelMessageService;
import com.sjksy.demo.vo.travel_contract.TravelContractInsertVo;
import com.sjksy.demo.vo.travel_contract.TravelContractShowVo;
import com.sjksy.demo.vo.travel_message.TravelInfoInsertVo;
import com.sjksy.demo.vo.travel_message.TravelMessageVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/travel_contract")
@Tag(name = "旅游合同接口",description = "旅游合同，旅游线路相关接口")
public class TravelContractController {

    @Resource
    TravelContractService travelContractService;
    @Resource
    TravelMessageService travelMessageService;

    @PostMapping("/insert_travel_contract")
    @Operation(summary = "插入旅游合同信息")
    ResponseEntity<String> insertTravelContract(@RequestBody TravelContractInsertVo travelContractInsertVo){
        if(travelContractService.insertTravelContract(travelContractInsertVo)){
            return ResponseEntity.ok("insert suc!!");
        }else {
            return ResponseEntity.badRequest().body("insert err!!");
        }
    }

    @GetMapping("/get_all_travel_contract")
    @Operation(summary = "展示所有合同信息")
    ResponseEntity<List<TravelContractShowVo>> getAllTravelContract(){
        List<TravelContractShowVo> travelContractShowVoList=travelContractService.getAllTravelContract();
        if(travelContractShowVoList==null){
            return ResponseEntity.notFound().build();
        }else {
            return ResponseEntity.ok(travelContractShowVoList);
        }
    }

    @PostMapping("/update_travel_contract")
    @Operation(summary = "修改合同信息")
    ResponseEntity<String> updateTravelContract(@RequestBody TravelContractInsertVo travelContractInsertVo){
        if(travelContractService.updateTravelContract(travelContractInsertVo)){
            return ResponseEntity.ok("update suc!!");
        }else {
            return ResponseEntity.badRequest().body("update err!!");
        }
    }


    @PostMapping("/insert_travel_info")
    @Operation(summary = "插入旅游信息")
    ResponseEntity<String> insertTravelInfo(@RequestBody TravelInfoInsertVo travelInfoInsertVo){
        if(travelMessageService.insertTravelInfo(travelInfoInsertVo)){
            return ResponseEntity.ok("insert suc!!");
        }else {
            return ResponseEntity.badRequest().body("insert err!!");
        }
    }

    @GetMapping("/get_all_travel_info")
    @Operation(summary = "展示所有旅游信息")
    ResponseEntity<List<TravelMessageVo>> getAllTravelInfo(){
        List<TravelMessageVo> travelMessageVoList=travelMessageService.getAllTravelInfo();
        if(travelMessageVoList==null){
            return ResponseEntity.notFound().build();
        }else {
            return ResponseEntity.ok(travelMessageVoList);
        }
    }

    @PostMapping("/update_travel_info")
    @Operation(summary = "修改旅游信息")
    ResponseEntity<String> updateTravelInfo(@RequestBody TravelInfoInsertVo travelInfoInsertVo){
        if(travelMessageService.updateTravelInfo(travelInfoInsertVo)){
            return ResponseEntity.ok("update suc!!");
        }else {
            return ResponseEntity.badRequest().body("update err!!");
        }
    }


}
